#include <mutex>
#include "render.h"

void Render::set_world2camera_pose(const Pose& world2camera_pose) {
  const std::lock_guard<std::mutex> lock{ mutex_ };
  world2camera_pose_ = world2camera_pose;
  camera2world_pose_ = world2camera_pose.inverse();
}

void Render::set_camera2world_pose(const Pose& camera2world_pose) {
  const std::lock_guard<std::mutex> lock{ mutex_ };
  camera2world_pose_ = camera2world_pose;
  world2camera_pose_ = camera2world_pose.inverse();
}

const cv::Mat& Render::normal_image() const {
	return normal_image_;
}

const cv::Mat& Render::silhouette_image() const {
	return silhouette_image_;
}

const cv::Mat& Render::depth_image() const {
	return depth_image_;
}

void Render::ClearDepthImage() {
	depth_image_.create(cv::Size{ intrinsics_.width, intrinsics_.height }, CV_16U);
	depth_image_.setTo(cv::Scalar{ 0 });
}

void Render::ClearSilhouetteImage() {
	silhouette_image_.create(cv::Size{ intrinsics_.width, intrinsics_.height }, CV_8U);
	silhouette_image_.setTo(cv::Scalar{ 0 });
}

void Render::ClearNormalImage() {
	normal_image_.create(cv::Size{ intrinsics_.width, intrinsics_.height }, CV_8UC4);
	normal_image_.setTo(cv::Vec4b{ 0, 0, 0, 0 });
}